package com.joker.aigc.dao;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joker.aigc.domain.entity.User;
import com.joker.aigc.mapper.UserMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class UserDao extends ServiceImpl<UserMapper, User> {

    public Map<Long, User> getBatch(List<Long> atUidList) {
        List<User> list = lambdaQuery().in(User::getId, atUidList).list();
        if (CollectionUtil.isNotEmpty(list)) {
            return list.stream().collect(Collectors.toMap(User::getId, item -> item));
        }
        return new HashMap<>();
    }

    /**
     * 用户是否都存在
     *
     * @param uids 用户id集合
     * @return 用户是否都存在
     */
    public Boolean usersAllExist(Set<Long> uids) {
        if (CollectionUtil.isEmpty(uids)) {
            return false;
        }
        List<User> users = lambdaQuery().in(User::getId, uids).list();
        return CollectionUtil.isNotEmpty(users) && users.size() == uids.size();
    }
}
